package com.lottery.dao.qiuqiu.lobbyDao;

import com.lottery.dto.BetDto;
import com.lottery.entity.Bettinginfo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

public interface BettinginfoDao {

	/**
	 * 查询bettinginfo投注详情表所有信息
	 * 
	 * @return
	 */
	List<Bettinginfo> selectBettinginfoList(String expect);

	/**
	 * 分页查询bettinginfo投注详情表所有信息
	 * 
	 * @param expect
	 * @param startCount
	 * @return
	 */
	List<Bettinginfo> selectBettinginfoPage(@Param(value = "expect") String expect,
                                            @Param("lotteyType") int lotteyType); // @Param(value = "startCount") int startCount,

	/**
	 * 根据userId查询bettinginfo投注详情表数据
	 *
	 * @return
	 */
	List<Bettinginfo> selectBettinginfoByUserId(int userId);

	/**
	 * 添加list到bettinginfo投注详情表
	 */
	void insertBettinginfoList(List<Bettinginfo> bettinginfoList);

	/**
	 * 修改中奖状态
	 */
	void updateBettinginfo(Bettinginfo bettinginfo);

	/**
	 * 根据userId和期号expect查询bettinginfo投注详情表数据
	 *
	 * @return
	 */
	List<Bettinginfo> selectBettinginfoByExpect(@Param(value = "userId") int userId,
                                                @Param(value = "expect") String expect, @Param("type") int type);

	/**
	 * 根据userId和期号expect统计投注总金额
	 */
	Double betTotalAmount(@Param(value = "userId") int userId, @Param(value = "expect") String expect);

	int selectUserBetCount(int userId);

	int selectUserbetWinCount(int userId);

	int selectUserbetAmount(int userId);

	List<BetDto> searchBetRecord(Map<String,Object> params);

	@Select("select IFNULL(SUM(bettingmoney),0) FROM bettinginfo where user_id = #{userId} and date_format(betting_date,'%Y-%m-%d') = #{date}")
	double searchYesterdayBet(@Param("userId") Integer userId,@Param("date") String date);

	@Select("SELECT IFNULL(SUM(l.winningamount),0) from lottery_exchange l LEFT JOIN bettinginfo b on l.bettinginfo_id = b.id where l.user_id = #{userId} and date_format(b.betting_date,'%Y-%m-%d') = #{date}")
	double searchYesterdayWin(@Param("userId") Integer userId,@Param("date") String date);

	List<Bettinginfo> selectBettinginfoForUser(Map<String,Object> params);

    Bettinginfo selectBetInfoById(String id)throws Exception;

    @Delete("delete from bettinginfo where id = #{id}")
	int deleteBetInfoById(String id);

    @Select("select count(*) from bettinginfo where bet_orderid = #{k}")
	int selectCountByOrderId(String k);

    @Select("select DATE_FORMAT(betting_date,'%Y-%m-%d') from bettinginfo where user_id = #{userId} and lottey_type =#{lotteyType} and DATE_FORMAT(betting_date,'%Y-%m-%d') between #{startTime} and #{endTime} GROUP BY DATE_FORMAT(betting_date,'%y-%m-%d') ;")
    List<String> selectDays(Map<String,Object> map);

	List<Bettinginfo> searchPastBetRecord(Map<String,Object> params);


	List<BetDto> serachForMouthCount(Map<String,Object> params);

	@Select("select count(*) from bettinginfo where user_id = #{userId} and lottey_type = #{lotteyType}")
	int selectRecordCount(@Param("userId") Integer userId,@Param("lotteyType") Integer lotteyType);

	List<Bettinginfo> searchAllbetRecordByUserID(Map<String,Object> params)throws Exception;

	@Select("SELECT expect from bettinginfo where user_id= #{userId} and state != 2 and  date_format(betting_date,'%Y-%m-%d') BETWEEN #{startTime} and #{endTime} GROUP BY expect")
	List<String> selectBetRecordDay(Map<String,Object> params);

	@Select("SELECT IFNULL(SUM(bettingmoney),0) from bettinginfo where user_id = #{userId}")
    double searchBetTotal(String userId);

	List<BetDto> searchRecordByUserId(Map<String,Object> params);


    void updateBetRobackStateYesterday(List<String> list);
}
